/* 
 * Copyright 2009 Shared Object (www.sharedobject.ch)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package edos.prm.process;

import edos.prm.artifact.Artifact;
import edos.prm.artifact.Attribute;
import edos.prm.engine.PRM;
import edos.prm.project.Topic;

/**
 * A Process is a program of operations of activities, either core activities
 * or process-defined activities.
 * <p>
 * A running process is termed a {@code Task}.
 * 
 */
public interface Process extends Artifact {
	
	public static final Process ROOT_PROCESS =
		new PrmProcess(new ProcessAction.NativeProcess(PRM.class,
				new Object[]{PRM.getProgramName()}),
				"Root Process", "Root");
	
	/**
	 * Returns the whole action chain for this Process
	 * 
	 * @return Process action chain
	 */
	public ProcessAction getDeclaredActions();
	
	@Attribute
	public Topic[] getTopics();
	
	public String getDescription();
	
	@Attribute
	public String getName();
	
	final static class PrmProcess implements Process {

		private String description;
		private String name;
		private Topic[] topics;
		private ProcessAction actions;
		
		PrmProcess(ProcessAction actions, String description, String name) {
			super();
			this.actions = actions;
			this.description = description;
			this.name = name;
		}

		public ProcessAction getDeclaredActions() {
			return this.actions;
		}

		public String getDescription() {
			return this.description;
		}

		public String getName() {
			return name;
		}

		public Topic[] getTopics() {
			return topics;
		}
		
		public void addTopic(Topic topic) {
			Topic[] newTopics = new Topic[topics.length + 1];
			for ( int i = 0; i< topics.length; i++ )
				newTopics[i] = topics[i];
			topics = newTopics;
		}
		
		public String toString() {
			return "PrmProcess: " + this.name;
		}
	}
}
